package com.jiayou.codec

import com.jiayou.message.ChannelMessage
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandler
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToByteEncoder
import org.springframework.stereotype.Component

/**
@author 李 双
@data   2020-11-18  16:10
@info
 */

class ChannelEncoder : MessageToByteEncoder<ChannelMessage>() {
    override fun encode(ctx: ChannelHandlerContext, msg: ChannelMessage, out: ByteBuf) {
        out.writeInt(msg.length)
        out.writeInt(msg.dataType.ordinal)
        out.writeBytes(msg.byteArray)
    }
}